#include "stdafx.h"
#include "About.h"
#include "resource.h"

//LRESULT ReferenceList::Reaction(UINT message, WPARAM wParam, LPARAM lParam){
	
//}

LicenseItem::LicenseItem(){
  SetSize(340,150);
  m_hIcon = NULL;
}

void LicenseItem::Draw(HDC hDC){
	RECT rc = m_Area;
	if(m_hIcon)::DrawIconEx(hDC, rc.left+10, rc.top+50,m_hIcon, 32, 32, 0, 0, DI_NORMAL);
	string s1= "Rock version 0.0.1 ";
	string s2 ="Copyright 2002-2007, All right reserved.";
	string s3 ="Developer: HongBing Zhang";
	string s4 ="Email: HongBing75@gmail.com";
	
	string s5 = "This is just a demo, use at your own risk. ";
	COLORREF crOld = ::SetTextColor(hDC,RGB(0,0,0));
	rc.left += 70;
	rc.top+=20;
	::DrawText(hDC,s1.c_str(),s1.size(),&rc,DT_LEFT|DT_SINGLELINE);
	rc.top+=25;
	::DrawText(hDC,s2.c_str(),s2.size(),&rc,DT_LEFT|DT_SINGLELINE);
	rc.top+=25;
	::DrawText(hDC,s3.c_str(),s3.size(),&rc,DT_LEFT|DT_SINGLELINE);
	rc.top+=25;
	::DrawText(hDC,s4.c_str(),s4.size(),&rc,DT_LEFT|DT_SINGLELINE);
    
	rc.left -=70;
	rc.top+=40;
	rc.bottom = rc.top+3;
    FillRect(hDC,rc,RGB(255,0,0));

    rc.top+=20;
	rc.bottom = rc.top+20;
	::DrawText(hDC,s5.c_str(),s5.size(),&rc,DT_LEFT|DT_SINGLELINE);
	::SetTextColor(hDC,crOld);
}     

CAbout::CAbout()
{
	m_Created = FALSE;
	HICON hIcon = ::LoadIcon(GetHinstance(),MAKEINTRESOURCE(IDI_TIP));
	SetIcon(hIcon);
	LicenseItem* HeaderItem = new LicenseItem;
	hIcon = ::LoadIcon(GetHinstance(),MAKEINTRESOURCE(IDI_ZHB1));
	HeaderItem->m_hIcon = hIcon;
	HeaderItem->m_Parent = &m_RefView;
	m_RefView.m_ChildList.push_back(HeaderItem);
//	ListItem* NewItem = m_RefView.AddItem("www.codeproject.com");
//	NewItem->m_Area.right=340;
}

CAbout::~CAbout()
{

}
void CAbout::Layout(bool Redraw /*= true*/){
	CWSFrameView::Layout(Redraw);
	if(m_Created){
		::MoveWindow(m_RefView.GetHwnd(),m_rcClient.left,m_rcClient.top,RectWidth(m_rcClient),RectHeight(m_rcClient),TRUE);
	}
};

LRESULT CAbout::Reaction(UINT message, WPARAM wParam, LPARAM lParam){

	switch(message){
	case WM_LBUTTONDOWN:
		return OnLButtonDown(wParam,lParam);
	case WM_CREATE:
		return OnCreate(wParam,lParam);
	default:
		return CWSFrameView::Reaction(message,wParam,lParam);
	}
}

LRESULT CAbout::OnCreate(WPARAM wParam, LPARAM lParam){
	RECT rc;
	::SetRect(&rc,0,0,0,0);
	if(!m_RefView.Create(GetHinstance(),NULL,WS_CHILD|WS_VISIBLE,rc,m_hWnd,10)){
		return -1;
	}
	m_Created = true;
	return 0;
}

LRESULT CAbout::OnLButtonDown(WPARAM wParam, LPARAM lParam) 
{
    POINTS* p = (POINTS*)(&lParam);
	POINT point;
	point.x = p->x;
	point.y = p->y;

    CSpace2 * Space = NcHit(point);	
	if(Space){
		int64 ID = Space->m_ID;
        switch(ID){
		case ID_CLOSE:
			{
			SendParentRectionMessage(WM_LBUTTONDOWN,wParam,lParam,Space);
			Destroy();
			}
			break;
		case ID_LEFTSIDE:
			//::SendMessage(m_hWnd,WM_NCLBUTTONDOWN,HTBOTTOMLEFT,MAKELPARAM(point.x,point.y));
            break;		
		case ID_RIGHTSIDE:
			//::SendMessage(m_hWnd,WM_NCLBUTTONDOWN,HTBOTTOMRIGHT,MAKELPARAM(point.x,point.y));
			break;
		case ID_BOTTOMSIDE:
			//::SendMessage(m_hWnd,WM_NCLBUTTONDOWN,HTBOTTOM,MAKELPARAM(point.x,point.y));
			break;
		case ID_TITLETEXT: //TextLabel
			::SendMessage(m_hWnd,WM_NCLBUTTONDOWN,HTCAPTION,MAKELPARAM(point.x,point.y));
			break;
		}
	}
    return 0;
}

